<!DOCTYPE html>
<html lang="en">
{include file="sunfc/public/headfile" /}
<body>

<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="min-width: 100%;width: auto;">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">帮助中心</li>
                            <li onclick="go('add_pro')">帮助新增</li>
                        </ul>
                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">

                            <div class="layui-tab-item layui-show">

                                <div>
                                    <div class="layui-btn-group">
                                        <button class="layui-btn" onclick="setStatus(0);" >隐藏</button>
                                        <button class="layui-btn" onclick="setStatus(1);" >展示</button>
                                    </div>
                                </div>

                                <div class="layadmin-trailer ">

                                    <table class="layui-table" lay-skin="line">

                                        <thead>
                                        <tr>
                                            <th></th>
                                            <th>#ID</th>
                                            <th>分类id</th>
                                            <th>标题</th>
                                            <th>详情</th>
                                            <th>展示状态</th>
                                            <th>创建时间</th>
                                            <!--<th>状态</th>-->
                                            <th></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="(item,index) in items" :data_id="item.id">
                                            <td style="width: 20px;text-align: center">
                                                <input type="checkbox" class="vue_index" name="id" :value="item.id"
                                                       style="zoom: 150%">
                                            </td>
                                            <td>{{item.id}}</td>
                                            <td>{{item.class_id}}</td>
                                            <td>{{item.title}}</td>
                                            <td>{{item.content}}</td>
                                            <td>
                                                <span v-if="item.is_show == 1">展示</span>
                                                <span v-if="item.is_show == 0">隐藏</span>
                                            </td>
                                            <td>{{item.create_time}}</td>
                                            <td>

                                                <div class="layui-btn-group">
                                                    <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                            :data_id="item.id" :data_index="index" onclick="edit(this)">编辑
                                                    </button>
                                                    <!--<button class="layui-btn layui-btn-sm layui-btn-primary"-->
                                                    <!--:data_id="item.id" :data_index="index">操作2-->
                                                    <!--</button>-->
                                                </div>

                                            </td>
                                        </tr>

                                        </tbody>
                                    </table>


                                </div>
                                <div id="demo7"></div>

                            </div>


                        </div>
                    </div>


                </div>


            </div>

        </div>


    </div>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            check: [],
            curr: 1,//当前页
            limit: 10,//当前页
            items: []
        }
    });

    function init() {
        layer.ready(function () {
            layer.load(2);
            $.get('/admin/sunfc.help/index', {page: app.curr, limit: app.limit},
                function (res) {
                    layer.closeAll();
                    app.items = res.data;
                }
            );
        });

    }

    layui.use('table', function () {
        var table = layui.table;
    });
    layui.use(['laypage', 'layer'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        //完整功能
        laypage.render({
            elem: 'demo7'
            , count: "{$count}"
            , limits: [10, 20]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                console.log(obj)
                app.curr = obj.curr;
                app.limit = obj.limit;
                init();

            }
        });

    });
    //查看弹框
    function edit(that) {

        var data_id = $(that).attr('data_id');
        layer.open({

            type: 2,
            title: '排序编辑',
            shadeClose: true,
            shade: 0.01,
            area: ['50%', '50%'],
            content: "{:url('helpEdit')}?id=" + data_id //iframe的url

        });


    }

    //获取下标
    function getCheckBox() {
        var check = [];
        $.each($('input[type=checkbox]:checked.vue_index'), function () {
            check.push($(this).val());
        });
        return check;
    };
    function setStatus(status) {

        var ids = getCheckBox();
        // alert(ids);
        if (ids.length > 0) {

            var index = layer.confirm('确认继续执行？', {
                btn: ['确定', '取消'] //按钮
            }, function () {

                $.post('{:url("/admin/sunfc.help/set_status")}', {ids: ids,is_show:status}, function (res) {
                    if (res.code == 1) {
                        //layer.msg(res.msg, {icon: 1})
                        //layer.msg(res.msg);
                        $("input:checkbox").removeAttr("checked");
                        init();
                    }
                    layer.close(index);

                });
            }, function () {
                layer.close(index);
            });
        }


    }

</script>
</body>
</html>